<%@ include file="/WEB-INF/jsp/include.jsp"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<a href="#" class="btn btn-primary"><i class="icon-plus icon-white"></i> Add User</a>

<table class="table table-hover table-condensed">
	<caption>List of signin users</caption>
	<thead>
		<tr>
			<th>#</th>
			<th>Username</th>
			<th>Email @</th>
			<th>SigninDate</th>
			<th>Role</th>
			<th>Status</th>
			<th>Actions</th>
		</tr>
	</thead>
	<tbody>
		<c:forEach var="user" items="${users}">
			 <c:choose>
                <c:when test="${user.enabled == false }">
				    <c:set var="disabled" value="error" />
			     </c:when>
                <c:otherwise>
                    <c:set var="disabled" value="" />
                </c:otherwise>
            </c:choose>
            
			<c:url var="delete_url" value="/admin/users/delete/${user.id}" />
			<c:url var="lock_url" value="/admin/users/block/${user.id}" />
            <c:url var="unlock_url" value="/admin/users/unblock/${user.id}" />            
			<c:url var="view_url" value="/user/profile/${user.id}" />

			<tr class="${disabled}">
				<td>${user.id}</td>
				<td>${user.userName}</td>
				<td>${user.email}</td>
				<td>${user.signinDate}</td>
				<td>${user.roleName}</td>
				<td>${user.enabled}</td>
				<td><a href="${view_url}"><i class="icon-eye-open"></i></a> 
				    <c:choose>
				        <c:when test="${user.enabled == false }">
				            <a href="${unlock_url}"><i class="icon-thumbs-up"></i></a> 
				        </c:when>
				        <c:otherwise>
				            <a href="${lock_url}"><i class="icon-lock"></i></a> 
				        </c:otherwise>
				    </c:choose>
				    <a href="${delete_url}"><i class="icon-trash"></i></a>
				</td>
			</tr>
		</c:forEach>
	</tbody>
</table>

<c:url var="firstUrl" value="/admin/users/pages/1" />
<c:url var="lastUrl" value="/admin/users/pages/${totalPages}" />
<c:url var="prevUrl" value="/admin/users/pages/${currentIndex - 1}" />
<c:url var="nextUrl" value="/admin/users/pages/${currentIndex + 1}" />

<div class="pagination">
	<ul>
		<c:choose>
			<c:when test="${currentIndex == 1}">
				<li class="disabled"><a href="#">&lt;&lt;</a></li>
				<li class="disabled"><a href="#">&lt;</a></li>
			</c:when>
			<c:otherwise>
				<li><a href="${firstUrl}">&lt;&lt;</a></li>
				<li><a href="${prevUrl}">&lt;</a></li>
			</c:otherwise>
		</c:choose>
		<c:forEach var="i" begin="${beginIndex}" end="${endIndex}">
			<c:url var="pageUrl" value="/admin/users/pages/${i}" />
			<c:choose>
				<c:when test="${i == currentIndex}">
					<li class="active"><a href="${pageUrl}"><c:out value="${i}" /></a></li>
				</c:when>
				<c:otherwise>
					<li><a href="${pageUrl}"><c:out value="${i}" /></a></li>
				</c:otherwise>
			</c:choose>
		</c:forEach>
		<c:choose>
			<c:when test="${currentIndex == totalPages}">
				<li class="disabled"><a href="#">&gt;</a></li>
				<li class="disabled"><a href="#">&gt;&gt;</a></li>
			</c:when>
			<c:otherwise>
				<li><a href="${nextUrl}">&gt;</a></li>
				<li><a href="${lastUrl}">&gt;&gt;</a></li>
			</c:otherwise>
		</c:choose>
	</ul>
</div>
